import java.lang.reflect.Field;

import org.junit.Before;

/**
 * created 31.01.08, 15:30
 * 
 * A Basic Test Class which provides the common setup stuff and some reflection 
 * 
 * @author koschka
 *
 */
public class BasicTest {
	protected GarageDoor gd;
	
	/**
	 * Set up the Tests
	 * 
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		gd = new GarageDoor();	
		
		// check if myDoorState exists
		getState();
	}
	
	/**
	 * Return the Content of the Attribute "myDoorState"
	 */
	public Object getState()
	{
		Class<?> c = gd.getClass();
		
		// Get attribute myDoorState, set the mode to accessible and return the content
		try{
			Field myField = c.getDeclaredField("myDoorState");
			myField.setAccessible(true);
			
			return myField.get(gd);
		}
		catch(NoSuchFieldException e)
		{
			throw new AssertionError("The class 'GarageGate' had to have an attribute 'myDoorState'");
		}	
		catch(Exception e)
		{
			e.printStackTrace();
			throw new AssertionError("Something internially got corrupted");
		}
	}
}
